<template>
    <AllOut>
        <div class="index2_content" v-loading="loading">
            <TopNav :show_links="true"></TopNav>
            <div class="content_out index_content" style="padding-top:84px;">
                <b-container fluid>
                    <b-row>
                        <b-col md="3" sm="12" class="">
                            <Asdise :refush="refush" :nav_value="0" @asdiseClick="asdiseClick" :companyData="{}" />
                        </b-col>
                        <b-col md="9" sm="12" class="">
                            <div class="flex index2-input-search-s" v-if="indexValue == 0">
                                <div class="index2-input-search">
                                    <el-input placeholder="搜索" v-model="inputValues" class="input-with-select"
                                        style="width: 420px;">
                                        <el-button slot="append" type="primary"
                                            style="color: #FFFFFF;border: 0px;border-radius: 0px;"
                                            icon="el-icon-search">搜索</el-button>
                                    </el-input>
                                    <!-- <div class="search">
                                        <el-input placeholder="搜索" v-model="inputValues" class="input-with-select">
                                            <el-button type="primary" slot="append" icon="el-icon-search"></el-button>
                                        </el-input>
                                    </div> -->
                                </div>
                            </div>
                            <div class="" style="margin-bottom: 28px;">
                                <IndexNav :show_number="indexValue" v-if="indexValue != 0" @indexNavClick="indexNavClick" />
                            </div>
                            <!-- 首页职位 -->
                            <div class="" v-if="indexValue == 0">
                                <Classification style="margin-bottom: 10px;" @ClassificationClick="ClassificationClick" />
                                <ClassAll style="margin-bottom: 10px;" @ClassAllClick="ClassAllClick" />
                                <Information v-for="(item, index) in rows" :key="index" :data="item"
                                    @collectionClick="collectionClick" :indexValue="indexValue" />
                                <el-empty
                                    style="width: 100%;height: 500px; background: #f8f9fa;border: 1px solid #CACFD6;margin: auto;"
                                    description="暂无数据" v-if="rows.length == 0" />
                                <div class="flex jcc aic" style="margin: 50px 0px;">
                                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                        :current-page="ruleFrom.pageNum" :page-sizes="[10, 20, 50, 100]"
                                        :page-size="ruleFrom.pageSize" layout="total, sizes, prev, pager, next, jumper"
                                        :total="total">
                                    </el-pagination>
                                </div>
                            </div>
                            <!-- 已投递、邀请投递、收藏 -->
                            <div class="" v-if="indexValue == 1 || indexValue == 2 || indexValue == 3">
                                <Information v-for="(item, index) in rows" :key="index" :data="item"
                                    @collectionClick="collectionClick" :indexValue="2" />
                                <el-empty
                                    style="width: 100%;height: 500px; background: #f8f9fa;border: 1px solid #CACFD6;margin: auto;"
                                    description="暂无数据" v-if="rows.length == 0" />
                                <div class="flex jcc aic" style="margin: 50px 0px;">
                                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                        :current-page="ruleFrom.pageNum" :page-sizes="[10, 20, 50, 100]"
                                        :page-size="ruleFrom.pageSize" layout="total, sizes, prev, pager, next, jumper"
                                        :total="total">
                                    </el-pagination>
                                </div>
                            </div>
                            <!-- 投递进度-->
                            <div class="" v-if="indexValue == 4">
                                <Information v-for="(item, index) in rows" :key="index" :data="item"
                                    @collectionClick="collectionClick" :indexValue="3" />
                                <el-empty
                                    style="width: 100%;height: 500px; background: #f8f9fa;border: 1px solid #CACFD6;margin: auto;"
                                    description="暂无数据" v-if="rows.length == 0" />
                                <div class="flex jcc aic" style="margin: 50px 0px;">
                                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                        :current-page="ruleFrom.pageNum" :page-sizes="[10, 20, 50, 100]"
                                        :page-size="ruleFrom.pageSize" layout="total, sizes, prev, pager, next, jumper"
                                        :total="total">
                                    </el-pagination>
                                </div>
                            </div>

                        </b-col>
                    </b-row>
                </b-container>
            </div>
        </div>
    </AllOut>
</template>

<script>

import { getInfo } from "@/api/login";
import { getlistRegistration, editRegistration, collections, registration, collection, positionList } from "@/api/my.js"
import { dictSect, dictFun } from "@/utils/dictUnit"
export default {
    data() {
        return {
            refush: false,
            indexTopValue: 1,
            indexValue: 0,//0首页1已投递2
            inputValues: "",
            ruleFrom: {
                pageNum: 1,
                pageSize: 10,
                // positionType: "1",
                positionName: "",
                positionClassify: "",//职位分类
                educationRequirements: "",//学历
                requirementsYears: "",//工作经验
                arrivalTime: "",//到岗时间
                urgentPosition: "0",
                salaryStart: "",//薪资开始
                salaryEnd: "",//薪资结束
            },
            form_i: {//邀请投递
                pageNum: 1,
                pageSize: 10,
                status: 0
            },
            form_d: {//已投递
                pageNum: 1,
                pageSize: 10,
                statusNe:0
            },
            form_c: {//收藏
                pageNum: 1,
                pageSize: 10,
            },
            form_h: {//投递简历
                pageNum: 1,
                pageSize: 10,
                statusGe: 1,
                statusLe: 2
            },
            loading: false,
            total: 0,
            rows: [],

        }
    },
    mounted() {
        this.positionListApi(this.ruleFrom)
        dictFun()
    },
    methods: {
        // --------------------------------------------------更新页面----------------------------------------
        info() {
            if (this.indexValue == 0) {//首页
                this.positionListApi(this.ruleFrom)
            } else if (this.indexValue == 1) {//已投递
                if (this.indexTopValue == 1) {
                    this.getlistApi_r(this.form_d)
                } else if (this.indexTopValue == 2) {
                    this.getlistApi_i(this.form_i)
                } else if (this.indexTopValue == 3) {
                    this.getlistApi_c(this.form_c)
                }
            } else if (this.indexValue == 4) {//投递进度
                this.getlistApi_h(this.form_h)
            }
        },
        // --------------------------------------------------点击表头-----------------------------------------
        indexNavClick(value) {
            this.indexTopValue = value.id
            switch (this.indexTopValue) {
                case 1:
                    console.log("表头-已投递");
                    this.form_d.pageNum = 1
                    this.refush = 1
                    this.getlistApi_r(this.form_d)
                    break;
                case 2:
                    console.log("表头-邀请投递");
                    this.form_i.pageNum = 1
                    this.refush = 2
                    this.getlistApi_i(this.form_i)
                    break;
                case 3:
                    this.refush = 3
                    console.log("表头-收藏");
                    this.form_c.pageNum = 1
                    this.getlistApi_c(this.form_c)
                    break;
                case 4:
                    console.log("表头-简历初筛");
                    this.form_h.statusGe = value.statusGe
                    this.form_h.statusLe = value.statusLe
                    this.form_h.pageNum = 1
                    this.getlistApi_h(this.form_h)
                    break;
                case 5:
                    console.log("表头-笔试");
                    this.form_h.statusGe = value.statusGe
                    this.form_h.statusLe = value.statusLe
                    this.form_h.pageNum = 1
                    this.getlistApi_h(this.form_h)

                    break;
                case 6:
                    console.log("表头-面试");
                    this.form_h.statusGe = value.statusGe
                    this.form_h.statusLe = value.statusLe
                    this.form_h.pageNum = 1
                    this.getlistApi_h(this.form_h)

                    break;
                case 7:
                    console.log("体检审查/录用");
                    this.form_h.statusGe = value.statusGe
                    this.form_h.statusLe = value.statusLe
                    this.form_h.pageNum = 1
                    this.getlistApi_h(this.form_h)

                    break;
                case 8:
                    console.log("待入职");
                    this.form_h.statusGe = value.statusGe
                    this.form_h.statusLe = value.statusLe
                    this.form_h.pageNum = 1
                    this.getlistApi_h(this.form_h)

                    break;

                default:
                    break;
            }
        },
        // --------------------------------------------------点击侧边栏----------------------------------------
        asdiseClick(value) {
            console.log(value);
            if (value == 3 || value == 4 || value == 5) {
                this.indexValue = value == 3 ? 1 : value == 4 ? 2 : 3
            } else if (value == 1) {
                this.indexValue = 4
            } else {
                this.indexValue = 0
            }

            if (this.indexValue == 0) {//首页
                this.ruleFrom.pageNum = 1
                this.positionListApi(this.ruleFrom)
            } else if (this.indexValue == 1 || this.indexValue == 2 || this.indexValue == 3) {//投递收藏邀请投递
                this.indexNavClick({ id: this.indexValue })
            } else if (this.indexValue == 4) {//投递进度
                this.indexTopValue = 4//表头显示第一个初筛
                this.form_h.pageNum = 1
                this.getlistApi_h(this.form_h)
            }

        },
        // ---------------------------------------------------点击首页搜索栏-----------------------------------
        ClassificationClick(value) {
            console.log(value);
            this.ruleFrom.positionClassify = value.positionClassify
            this.ruleFrom.educationRequirements = value.educationRequirements
            this.ruleFrom.requirementsYears = value.requirementsYears
            this.ruleFrom.arrivalTime = value.arrivalTime
            this.positionListApi(this.ruleFrom)
        },
        // ------------------------------------------------------点击全部职位和紧急职位--------------------------
        ClassAllClick(value) {
            this.ruleFrom.urgentPosition = value.urgentPosition
            this.positionListApi(this.ruleFrom)
        },
        // ------------------------------------------------------点击公司类别------------------------------------
        blurClick() {
            console.log("公司类别", this.ruleFrom.positionType);
            this.positionListApi(this.ruleFrom)
        },
        // -------------------------------------------------分页-----------------------------------------------
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            if (this.indexValue == 0) {//首页
                this.ruleFrom.pageSize = val
                this.positionListApi(this.ruleFrom)
            } else if (this.indexValue == 1) {//已投递
                switch (this.indexTopValue) {
                    case 1:
                        console.log("分页size-已投递");
                        this.form_d.pageSize = val
                        this.getlistApi_r(this.form_d)
                        break;
                    case 2:
                        console.log("分页size-邀请投递");
                        this.form_i.pageSize = val
                        this.getlistApi_i(this.form_i)
                        break;
                    case 3:
                        console.log("分页size-收藏");
                        this.form_c.pageSize = val
                        this.getlistApi_c(this.form_c)
                        break;
                }
            } else if (this.indexValue == 4) {//投递进度
                this.form_h.pageSize = val
                this.getlistApi_h(this.form_h)
            }
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            if (this.indexValue == 0) {//首页
                this.ruleFrom.pageNum = val
                this.positionListApi(this.ruleFrom)
            } else if (this.indexValue == 1) {//已投递
                switch (this.indexTopValue) {
                    case 1:
                        console.log("分页num-已投递");
                        this.form_d.pageNum = val
                        this.getlistApi_r(this.form_d)
                        break;
                    case 2:
                        console.log("分页num-邀请投递");
                        this.form_i.pageNum = val
                        this.getlistApi_i(this.form_i)
                        break;
                    case 3:
                        console.log("分页num-收藏");
                        this.form_c.pageNum = val
                        this.getlistApi_c(this.form_c)
                        break;
                }
            } else if (this.indexValue == 4) {//投递进度
                this.form_h.pageNum = val
                this.getlistApi_h(this.form_h)
            }
        },
        // --------------------------------------------------api------------------------------------------------
        getlistApi_c(params) { //收藏列表
            this.loading = true
            collection(params).then((res) => {
                console.log("收藏列表：", res);
                this.loading = false
                // this.HeadersData[0].number = res.total
                this.rows = res.rows
                this.total = res.total
            })
        },
        getlistApi_r(params) { //已投递
            this.loading = true
            registration(params).then((res) => {
                console.log("已投递", res);
                this.loading = false
                // this.HeadersData[0].number = res.total
                this.rows = res.rows
                this.total = res.total
            })
        },
        getlistApi_i(params) { //邀请投递
            this.loading = true
            registration(params).then((res) => {
                console.log("邀请投递：", res);
                this.loading = false
                // this.HeadersData[0].number = res.total
                this.rows = res.rows
                this.total = res.total
            })
        },
        getlistApi_h(params) {//投递进度
            this.loading = true
            getlistRegistration(params).then((res) => {
                console.log("投递进度：", res);
                this.loading = false
                // this.HeadersData[0].number = res.total
                this.rows = res.rows
                this.total = res.total
            })
        },
        async positionListApi(params) {//首页职位投递
            this.loading = true
            await positionList(params).then(res => {
                this.loading = false
                console.log(res);
                this.total = res.total
                this.rows = res.rows
            })
        },
        // ----------------------------------------------------//收藏职位-----------------------------------------------
        collectionClick(value) {
            if (value == "refush") {
                this.getlistApi_h(this.form_h)
            } else {
                this.collectionApi(value)
            }
        },
        collectionApi(id) {
            collections({ positionId: id }).then(res => {
                this.$message({
                    message: `${res.msg}`,
                    type: 'success',
                });
                this.info()
                this.getInfo_()
            }).catch(res => {
                this.$message({
                    message: `${res.msg}`,
                    type: 'error',
                });
            })
        },
        getInfo_() {
            this.refush = !this.refush
            getInfo().then(res => {
                console.log("个人信息", res);
                sessionStorage.setItem("myInfornation", JSON.stringify(res.data))
            })
        },
    }
}
</script>

<style lang="scss" scoped>
// .search {
//     width: 100%;
//     // height: 100%;
//     background: #FFFFFF;
//     border-radius: 8px 8px 8px 8px;
//     opacity: 1;
//     overflow: hidden;
//     position: relative;

//     .el-select {
//         width: 100%;
//     }

//     .el-input__inner {
//         width: 100%;
//         border: 0px solid #2F6CBC;
//     }

//     .el-input-group__append {
//         border-radius: 0px 0px 0px 8px;
//         height: 100%;
//         position: absolute;
//         right: 10px;
//         top: 8px;
//         background-color: #2f6cbc;
//         color: #FFFFFF;

//         .el-button {
//             position: absolute;
//             height: 100%;
//             border-radius: 0px;
//             background-color: #2f6cbc;
//         }
//     }
// }

.index2_content {
    position: relative;
}

.index2-input-search-s {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 28px;
}

// .index2-input-search {
//     position: relative;
//     display: flex;
//     width: 500px;
//     justify-content: flex-end;
//     height: 40px;
//     right: 0;
//     background: #FFFFFF;
//     border-radius: 8px 8px 8px 8px;
//     opacity: 1;
//     border: 1px solid #2F6CBC;
// }
</style>